#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4+10;

string name[maxn];
map<string, int> id;
vector<int> dep[maxn], deped[maxn];
int stat[maxn];
list<int> l;

int cnt;
int ID(const string& s){
    if(!id.count(s)){
        id[s] = ++cnt;
        name[cnt] = s;
    }
    return id[s];
}

void init(){
    cnt = 0;
    for (int i=0; i<maxn; ++i){
        stat[i] = 0;
        name[i].clear();
        dep[i].clear(); deped[i].clear();
    }
    id.clear();
    l.clear();
}


bool IsDepended(int i){
    for (auto j:deped[i]) if(stat[j]) return true;
    return false;
}

void install(int i, bool exp){
    for (int de : dep[i]) {
        if(!stat[de]) {
            install(de, false);
        }
    }
    cout << "   Installing " << name[i] << "\n";
    l.push_back(i);
    stat[i] = exp? 1:2;
}

void remove(int i){
    cout << "   " << "Removing " << name[i] << "\n";
    stat[i] = 0;
    l.erase(find(l.begin(), l.end(), i));

    for (auto de:dep[i]){
        if(!IsDepended(de) && stat[de]==2) remove(de);
    }
}

int main() {
    //ios_base::sync_with_stdio(false);cin.tie(nullptr);
    string str;
    init();
    while(getline(cin, str)){
        cout << str << "\n";
        stringstream ss;
        switch(str[0]){
            case 'D':{
                ss.str(str.substr(7));
                string s1; ss >> s1; int it1 = ID(s1);
                string s2;
                while(ss >> s2){
                    int it2 = ID(s2);
                    dep[it1].push_back(it2);
                    deped[it2].push_back(it1);
                }
                break;
            }
            case 'I':{
                ss.str(str.substr(7));
                string s; ss >> s;
                int i = ID(s);
                if(stat[i]) cout << "   " << s << " is already installed.\n";
                else install(i, true);
                break;
            }
            case 'R':{
                ss.str(str.substr(7));
                string s; ss >> s;
                int i = ID(s);

                if(!stat[i]) cout << "   " << s << " is not installed.\n";
                else{
                    if(IsDepended(i)) cout << "   " << s << " is still needed.\n";
                    else remove(i);
                }

                break;
            }
            case 'L':{
                for (auto i:l) cout << "   " << name[i] << "\n";
                break;
            }
            case 'E':{
                init();
                break;
            }
        }
    }
    return 0;
}